package com.xjj.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjj.entity.Vote;
import com.xjj.mapper.VoteMapper;
import com.xjj.service.AppVoteService;
import com.xjj.vo.VotingVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @ClassName AppVoteServiceImpl
 * @Description TODO
 * @Author GH
 * @Date 2022/10/27 12:08
 * @Version 1.0
 **/
@Service
@Transactional
public class AppVoteServiceImpl extends ServiceImpl<VoteMapper,Vote> implements AppVoteService {
    @Resource
    private VoteMapper voteMapper;
    @Override
    public void addStudentVote(VotingVo votingVo) {
        //修改数据库数据
        Integer studentId = votingVo.getStudentId();
        Integer voteId = votingVo.getVoteId();
        Integer[] optionsId = votingVo.getOptionsId();
        for (Integer optionId : optionsId) {
            voteMapper.addStudentVote(optionId,studentId,voteId);
        }
    }

    @Override
    public boolean hasVoting(Integer studentId, Integer voteId) {
        Integer count = voteMapper.hasVoting(studentId, voteId);
        if(count==0){
            return false;
        }else {
            return true;
        }
    }
}
